using System.Collections;
using System.Collections.Generic;
using UnityEngine;

namespace LS.GameKit
{
    public class Collision3DBehaviour : Physics3DBehaviour
    {
        private void OnCollisionEnter(Collision collision)
        {
            var other = collision.collider;
            bool isTrigger = other.isTrigger;
            if (!castTrigger && !isTrigger) return;
            if (!castCollision && !isTrigger) return;
            if (!castLayers.LayerCast(1 << other.gameObject.layer)) return;
            var result = new Collision3DResult(collision);
            DoEnter(result);
        }

        private void OnCollisionStay(Collision collision)
        {
            var result = FindResult(collision.collider);
            if (result != null)
            {
                DoUpdate(result);
            }
        }

        private void OnCollisionExit(Collision collision)
        {
            var result = FindResult(collision.collider);
            if (result != null)
            {
                DoExit(result);
            }
        }
    }
}
